//
//  UIScrollView+PullToRefresh.m
//  Local
//
//  Created by 刘铎 on 14-1-9.
//  Copyright (c) 2014年 上海即略网络信息科技有限公司. All rights reserved.
//

#import "UIScrollView+PullToRefresh.h"
#import <objc/runtime.h>

static void *RefreshHeaderViewPorpertyKey = (void *)@"RefreshHeaderViewPorpertyKey";
static void *LoadMoreFooterViewPorpertyKey = (void *)@"LoadMoreFooterViewPorpertyKey";

@implementation UIScrollView (PullToRefresh)

- (MJRefreshHeaderView *)refreshHeaderView {
    return objc_getAssociatedObject(self, RefreshHeaderViewPorpertyKey);
}

- (void)setRefreshHeaderView:(MJRefreshHeaderView *)refreshHeaderView {
    objc_setAssociatedObject(self, RefreshHeaderViewPorpertyKey, refreshHeaderView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (MJRefreshFooterView *)loadMoreFooterView {
    return objc_getAssociatedObject(self, LoadMoreFooterViewPorpertyKey);
}

- (void)setLoadMoreFooterView:(MJRefreshFooterView *)loadMoreFooterView {
    objc_setAssociatedObject(self, LoadMoreFooterViewPorpertyKey, loadMoreFooterView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)scrollToBottomAnimated:(BOOL)animated {
    CGPoint bottomOffset = CGPointMake(0, self.contentSize.height - self.bounds.size.height);
    [self setContentOffset:bottomOffset animated:YES];
}

//- (void)addRefreshHeaderWithRefreshBlock:(void (^)(MJRefreshBaseView *refreshView))refreshBlock {
//    MJRefreshHeaderView *header = [MJRefreshHeaderView header];
//    header.scrollView = self;
//    header.beginRefreshingBlock = refreshBlock;
//    header.endStateChangeBlock = nil;
//    header.refreshStateChangeBlock = nil;
//    [header beginRefreshing];
//    self.refreshHeaderView = header;
//}

//- (void)addLoadMoreFooterWithLoadMoreBlock:(void (^)(MJRefreshBaseView *refreshView))loadMoreBlock {
//    MJRefreshFooterView *footer = [MJRefreshFooterView footer];
//    footer.scrollView = self;
//    footer.beginRefreshingBlock = loadMoreBlock;
//    self.loadMoreFooterView = footer;
//}

@end
